package com.gx.smart.building.ui.maintain.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemMaintainRecordLayoutBinding;
import com.huishi.gx.ib.grpc.lib.ib.app.plantask.v1.dto.PlanTaskDto;

/**
 * @author xiaosy
 * @create 2020/5/8
 * @Describe 维修详情
 **/
public class MaintainRecordAdapter extends BaseAdapter<PlanTaskDto, MaintainRecordAdapter.ViewHolder> {
    public MaintainRecordAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_maintain_record_layout;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemMaintainRecordLayoutBinding binding = ItemMaintainRecordLayoutBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, PlanTaskDto item, int position) {
        holder.binding.planName.setText(item.getPlanName());
        holder.binding.taskCode.setText("任务编号：" + item.getTaskCode());
        holder.binding.deviceHandledCount.setText("设备保养进度: " + item.getDeviceHandledCount() + "/" + item.getDeviceTotal());

        //状态：1-已完成，2-未完成
        if (item.getHandleStatus() == 2) {
            String validTime = TimeUtils.millis2String(item.getValidTime(), "yyyy-MM-dd HH:mm");
            String invalidTime = TimeUtils.millis2String(item.getInvalidTime(), "yyyy-MM-dd HH:mm");
            holder.binding.time.setText("执行时间：" + validTime + "-" + invalidTime);//执行时间：2022-05-01 12:00 — 2022-05-10 12:00
            holder.binding.remainTime.setText("剩余：" + item.getValidDurationDesc());
            holder.binding.remainTime.setVisibility(View.VISIBLE);
        } else {
            String handleTime = TimeUtils.millis2String(item.getHandleTime(), "yyyy-MM-dd HH:mm");
            holder.binding.time.setText("完成时间：" + handleTime);//执行时间：2022-05-01 12:00 — 2022-05-10 12:00
            holder.binding.remainTime.setVisibility(View.GONE);
        }

    }

    protected static class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemMaintainRecordLayoutBinding binding;

        public ViewHolder(ItemMaintainRecordLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
